<!--
 * @Author: coman
 * @LastEditors: coman
 * @Date: 2020-06-18 19:58:42
 * @motto: No pain,No gain
 * @LastEditTime: 2020-06-18 20:22:04
--> 
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
   
    <!-- 统计字符串中每个字符的个数？以对象的形式返回 -->
    <script>
    function countLetter(str){
        var str1 = str.split("");
        
        var res=str1.reduce(function(pre,cur){
            // console.log(pre);
            
            if(pre[cur]){
                pre[cur]++;
            }else{
                pre[cur]=1;
            }
            return pre;
        },{})
        return res;
    }
    var str = 'abcdacbabcbababcbabcabd';
    console.log(countLetter(str));
    
</script>
</body>
</html>